package com.sunda.spmsweb.oaservice;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sunda.spmscommon.service.ISysLogService;
import com.sunda.spmsuser.entity.SpmsUser;
import localhost.services.ExtHrmresources.AnyType2AnyTypeMapEntry;
import localhost.services.ExtHrmresources.ExtHrmresourcesPortTypeProxy;
import localhost.services.RequestService.RequestServicePortTypeProxy;
import localhost.services.WorkflowData.WorkflowDataPortTypeProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

import javax.annotation.PostConstruct;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.sunda.spmscommon.Constans.*;

/**
 * @program: spms
 * @description: OaServiceImpl
 * @author: Wayne Wu
 * @create: 2021-03-01 18:48
 **/
@Component
public class OaService {

    @Autowired
    ISysLogService iSysLogService;

    // 静态初使化当前类
    public static OaService oaService;

    //注解@PostConstruct，这样方法就会在Bean初始化之后被Spring容器执行
    @PostConstruct
    public void init() {
        oaService = this;
    }

    /** 开发测试环境 OA 审批流对应流程ID */
//    String workflow0915 = "520";

    /** 生产环境 OA 审批流对应流程ID */
    String workflow0915 = "520";


    /***
     * 根据用户工号，向OA系统请求获取用户详细信息
     * @param userId
     * @return
     */
    public Map<String, Object> getUserInfo(String userId) {
        Map<String, Object> map = new HashMap<>();
        ExtHrmresourcesPortTypeProxy extHrmresourcesPortTypeProxy = new ExtHrmresourcesPortTypeProxy();
        try {
        	AnyType2AnyTypeMapEntry[] sss = extHrmresourcesPortTypeProxy.getUserInfoByWorkcode(userId);
        	JSONArray array = (JSONArray) JSON.toJSON(sss);
        	System.out.println("===1===" + array.toString());
            if (array.size() == 0 || "[]".equals(array.toString()) || "{}".equals(array.getJSONObject(0).toJSONString())){
                return null;
            }
            for (int i = 0; i < array.size(); i ++){
                //System.out.println(array.getJSONObject(i));
                if ("workcode".equals(array.getJSONObject(i).getString("key"))){
                    map.put("userId", array.getJSONObject(i).getString("value"));
                }
                if ("id".equals(array.getJSONObject(i).getString("key"))){
                    map.put("workId", array.getJSONObject(i).getString("value"));
                }
                if ("name".equals(array.getJSONObject(i).getString("key"))){
                    map.put("lastName", array.getJSONObject(i).getString("value"));
                }
                if ("telephone".equals(array.getJSONObject(i).getString("key"))){
                    map.put("telephone", array.getJSONObject(i).getString("value"));
                }
                if ("mobile".equals(array.getJSONObject(i).getString("key"))){
                    map.put("mobile", array.getJSONObject(i).getString("value"));
                }
                if ("email".equals(array.getJSONObject(i).getString("key"))){
                    map.put("email", array.getJSONObject(i).getString("value"));
                }
                if ("jobtitleid".equals(array.getJSONObject(i).getString("key"))){
                    map.put("positionId", array.getJSONObject(i).getString("value"));
                }
                if ("jobtitlename".equals(array.getJSONObject(i).getString("key"))){
                    map.put("positionName", array.getJSONObject(i).getString("value"));
                }
                if ("departmentid".equals(array.getJSONObject(i).getString("key"))){
                    map.put("deptId", array.getJSONObject(i).getString("value"));
                }
                if ("departmentname".equals(array.getJSONObject(i).getString("key"))){
                    map.put("deptName", array.getJSONObject(i).getString("value"));
                }
                if ("subcompanyid".equals(array.getJSONObject(i).getString("key"))){
                    map.put("subcompanyId", array.getJSONObject(i).getString("value"));
                }
                if ("subcompanyname".equals(array.getJSONObject(i).getString("key"))){
                    map.put("subcompanyName", array.getJSONObject(i).getString("value"));
                }
                if ("company".equals(array.getJSONObject(i).getString("key"))){
                    map.put("company", array.getJSONObject(i).getString("value"));
                }
                if ("point".equals(array.getJSONObject(i).getString("key"))){
                    map.put("branchPoint", array.getJSONObject(i).getString("value"));
                }
                if ("line".equals(array.getJSONObject(i).getString("key"))){
                    map.put("branchLine", array.getJSONObject(i).getString("value"));
                }
                if ("managerid".equals(array.getJSONObject(i).getString("key"))){
                    map.put("managerId", array.getJSONObject(i).getString("value"));
                }
                if ("managername".equals(array.getJSONObject(i).getString("key"))){
                    map.put("managerName", array.getJSONObject(i).getString("value"));
                }
                if ("status".equals(array.getJSONObject(i).getString("key"))){
                    map.put("oaStatus", array.getJSONObject(i).getString("value"));
                }
            }
            return map;
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }

    /**
     * 返回 OA 处理结果代码，小于等于 0 则失败；
     * -1：创建流程失败
     * -2：用户没有流程创建权限
     * -3：创建流程基本信息失败
     * -4：保存表单主表信息失败
     * -5：更新紧急程度失败
     * -6：流程操作者失败
     * -7：流转至下一节点失败
     * -8：节点附加操作失败
     * @param jsonObject
     * @param spmsId
     * @param spmsUser
     * @return
     */
    public int createRequest(JSONObject jsonObject, String spmsId, SpmsUser spmsUser,
                             String workflow0703, String workflow1201, String workflow3601){
        if (!jsonObject.getJSONObject("orderWerks").containsKey("oaProcessId") || jsonObject.getJSONObject("orderWerks").getString("oaProcessId").length() == 0){
            return 0;
        }
        String oaProcessId = jsonObject.getJSONObject("orderWerks").getString("oaProcessId");
        JSONObject doc = jsonObject.getJSONObject("orderWerks");
        if ("0703".equals(oaProcessId)){
            /** OA workflow id 0703 : 580 开发测试；240 正式；  */
            return createRequest0703(doc, spmsId, spmsUser, workflow0703);
        }
        if ("1201".equals(oaProcessId)){
            /** OA workflow id 1201 : 589 开发测试；262 正式； */
            return createRequest1201(doc, spmsId, spmsUser, workflow1201);
        }
        if ("3601".equals(oaProcessId)){
            /** OA workflow id 3601 : 592 开发测试；353 正式； */
            return createRequest3601(doc, spmsId, spmsUser, workflow3601);
        }
        return 0;
    }

    /** 被驳回的工厂请购单——状态 4，经机电主任修改后重新提交OA系统，新状态为：7 —— 重新提交 OA；待完成； */
    public boolean reSubmitOa(JSONObject doc, SpmsUser spmsUser,
                              String workflow0703, String workflow1201, String workflow3601){
        try {
            RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
            String oaProcessId = doc.getJSONObject("orderWerks").getString("oaProcessId");
            String oaBianhao = doc.getJSONObject("orderWerks").getString("oaBianhao");
            String spmsId = doc.getJSONObject("orderWerks").getString("spmsId");
            RequestInfo reqinfo = new RequestInfo();
            reqinfo.setCreatorid(spmsUser.getWorkId());
            if ("0703".equals(oaProcessId)){
                reqinfo.setWorkflowid(workflow0703);
            }
            if ("1201".equals(oaProcessId)){
                reqinfo.setWorkflowid(workflow1201);
            }
            if ("3601".equals(oaProcessId)){
                reqinfo.setWorkflowid(workflow3601);
            }
            reqinfo.setRequestlevel(doc.getString("urgency"));
            reqinfo.setRemindtype("0");
            reqinfo.setIsNextFlow("1");
            reqinfo.setDescription(doc.getString("subject"));
            /** 请求OA内容记录 */
            oaService.iSysLogService.addSubmitOaRecord("3", SPMS_RE_SUBMIT_OA, "添加", spmsUser.getUserId(),
                    "com.sunda.spmsweb.oaservice.reSubmitOa()", "", JSON.toJSONString(reqinfo), "WebService", doc.toJSONString(), spmsId);
            return wfproxy.nextNodeBySubmit(reqinfo, Integer.parseInt(oaBianhao), Integer.parseInt(spmsUser.getWorkId()), "");
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public int createRequest0703(JSONObject doc, String spmsId, SpmsUser spmsUser, String workflow0703){
		RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
		try {
			RequestInfo reqinfo = new RequestInfo();
			reqinfo.setCreatorid(spmsUser.getWorkId());
			reqinfo.setWorkflowid(workflow0703);
			reqinfo.setRequestlevel(doc.getString("urgency"));
			reqinfo.setRemindtype("0");
			reqinfo.setIsNextFlow("1");
			reqinfo.setDescription(doc.getString("subject"));

			Map<String, Object> map = new HashMap<>();
			map.put("zd2", doc.getString("applicationDate"));
            map.put("zd4", spmsUser.getWorkId());
            //map.put("zd7", spmsUser.getSubcompanyId() == null ? "" : spmsUser.getSubcompanyId());
            /** 分公司字段取值修改 20210804 */
            map.put("zd7", spmsUser.getCompany() == null ? "" : spmsUser.getCompany());
            map.put("zd8", spmsUser.getBranchPoint() == null ? "" : spmsUser.getBranchPoint());
            map.put("zd9", spmsUser.getBranchLine() == null  ? "" : spmsUser.getBranchLine());
            map.put("zd5", spmsUser.getDeptId() == null  ? "" : spmsUser.getDeptId());
            map.put("zd6", spmsUser.getPositionId() == null  ? "" : spmsUser.getPositionId());
            map.put("zd3", spmsUser.getUserId());
            map.put("zd11", doc.get("justification") == null ? "" : doc.getString("justification"));
            map.put("xmh", doc.get("projectCode") == null ? "" : doc.getString("projectCode"));
            map.put("cgdd", doc.get("purchaseLocation") == null ? 0 : Integer.parseInt(doc.getString("purchaseLocation")));
            map.put("sqlb", doc.get("applicationType") == null ? 0 : (doc.getString("applicationType").length() == 0 ? 0 : Integer.parseInt(doc.getString("applicationType"))));
            map.put("yjfy", doc.get("estimateCost") == null ? 0.00 : (doc.getString("estimateCost").length() == 0 ? 0.00 : Double.parseDouble(doc.getString("estimateCost"))));
            map.put("spmsurl", "");
            map.put("dj", 0);
            //map.put("zd11", "");
            map.put("je", 0);
            map.put("zd10", "");
            map.put("xglc", "");
            map.put("xgfj", "");
            map.put("cgy", "");
            map.put("spmsordernum", spmsId);

			MainTableInfo wmi = new MainTableInfo();
			Property[] wrti = new Property[map.size()];
            int i = 0;
            for (Map.Entry<String, Object> entry : map.entrySet()){
                wrti[i] = new Property();
                wrti[i].setName(entry.getKey());
                wrti[i].setValue(entry.getValue().toString());
                i ++;
            }
			wmi.setProperty(wrti);
			reqinfo.setMainTableInfo(wmi);

            /** 请求OA内容记录 */
            oaService.iSysLogService.addSubmitOaRecord("3", SPMS_SUBMIT_OA, "添加", spmsUser.getUserId(),
                    "com.sunda.spmsweb.oaservice.createRequest0703()", "", JSON.toJSONString(reqinfo), "WebService", doc.toJSONString(), spmsId);

             // 生成待办 ，返回待办id
			String reqid = wfproxy.createRequest(reqinfo);
            // 返回大于0 的数字则调用成功
			System.out.println("reqid ======== " + reqid);
            return Integer.parseInt(reqid);
		} catch (Exception e) {
            e.printStackTrace();
			System.out.println(e.getMessage());
            return 0;
		}
    }

    public int createRequest1201(JSONObject doc, String spmsId, SpmsUser spmsUser, String workflow1201){
        RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
        try {
            RequestInfo reqinfo = new RequestInfo();
            reqinfo.setCreatorid(spmsUser.getWorkId());
            /** OA workflow id 1201 : 589 测试；262 正式； */
            reqinfo.setWorkflowid(workflow1201);
            reqinfo.setRequestlevel(doc.getString("urgency"));
            reqinfo.setRemindtype("0");
            reqinfo.setIsNextFlow("1");
            reqinfo.setDescription(doc.getString("subject"));

            Map<String, Object> map = new HashMap<>();
            map.put("riqi", doc.getString("applicationDate"));
            map.put("shenqingren", spmsUser.getWorkId());
            map.put("bumen", spmsUser.getDeptId() == null  ? "" : spmsUser.getDeptId());
            map.put("zhiwu", spmsUser.getPositionId() == null  ? "" : spmsUser.getPositionId());
            //OA流程所需，前台不展示，传空
            map.put("fybm", 0);
            //OA新增
            map.put("fybmspms", "");
            map.put("xmlx", doc.get("projectType") == null ? 0 : (doc.getString("projectType").length() == 0 ? 0 : Integer.parseInt(doc.getString("projectType"))));
            map.put("status", doc.get("projectStatus") == null ? 0 : (doc.getString("projectStatus").length() == 0 ? 0 : Integer.parseInt(doc.getString("projectStatus"))));
            map.put("sfhy", doc.get("shippingType") == null ? 0 : (doc.getString("shippingType").length() == 0 ? 0 : Integer.parseInt(doc.getString("shippingType"))));
            map.put("devicetype", doc.get("deviceType") == null ? 0 : (doc.getString("deviceType").length() == 0 ? 0 : Integer.parseInt(doc.getString("deviceType"))));
            map.put("xmh", doc.get("projectCode") == null ? "" : doc.getString("projectCode"));
            map.put("cgdd", doc.get("purchaseLocation") == null ? 0 : Integer.parseInt(doc.getString("purchaseLocation")));
            map.put("sqlb", doc.get("applicationType") == null ? 0 : (doc.getString("applicationType").length() == 0 ? 0 : Integer.parseInt(doc.getString("applicationType"))));
            map.put("sbqd", doc.get("deviceStatement") == null ? "" : doc.getString("deviceStatement"));
            map.put("cgzje", doc.get("estimateCost") == null ? 0 : (doc.getString("estimateCost").length() == 0 ? 0 : Double.parseDouble(doc.getString("estimateCost"))));
            map.put("remark",doc.get("comments") == null ? "" : doc.getString("comments"));
            map.put("bianhao", "");
            map.put("spmsordernum", spmsId);
            map.put("xiangguanfujian", "");
            map.put("spmsurl", "");

            MainTableInfo wmi = new MainTableInfo();
            Property[] wrti = new Property[map.size()];
            int i = 0;
            for (Map.Entry<String, Object> entry : map.entrySet()){
                wrti[i] = new Property();
                wrti[i].setName(entry.getKey());
                wrti[i].setValue(entry.getValue().toString());
                i ++;
            }
            wmi.setProperty(wrti);
            reqinfo.setMainTableInfo(wmi);

            /** 请求OA内容记录 */
            oaService.iSysLogService.addSubmitOaRecord("3", SPMS_SUBMIT_OA, "添加", spmsUser.getUserId(),
                    "com.sunda.spmsweb.oaservice.createRequest1201()", "", JSON.toJSONString(reqinfo), "WebService", doc.toJSONString(), spmsId);

            // 生成待办 ，返回待办id
            String reqid = wfproxy.createRequest(reqinfo);
            // 返回大于0 的数字则调用成功
            System.out.println("reqid ======== " + reqid);
            return Integer.parseInt(reqid);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
            return 0;
        }
    }

    public int createRequest3601(JSONObject doc, String spmsId, SpmsUser spmsUser, String workflow3601){
        RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
        try {
            RequestInfo reqinfo = new RequestInfo();
            reqinfo.setCreatorid(spmsUser.getWorkId());
            /** OA workflow id 3601 : 592 测试；353 正式； */
            reqinfo.setWorkflowid(workflow3601);
            reqinfo.setRequestlevel(doc.getString("urgency"));
            reqinfo.setRemindtype("0");
            reqinfo.setIsNextFlow("1");
            reqinfo.setDescription(doc.getString("subject"));

            Map<String, Object> map = new HashMap<>();
            map.put("riqi", doc.getString("applicationDate"));
            map.put("shenqingren", spmsUser.getWorkId());
            map.put("bumen", spmsUser.getDeptId() == null  ? "" : spmsUser.getDeptId());
            map.put("zhiwu", spmsUser.getPositionId() == null  ? "" : spmsUser.getPositionId());
            map.put("gonghao", spmsUser.getUserId());
            map.put("xmzt", doc.get("projectStatus") == null ? 0 : (doc.getString("projectStatus").length() == 0 ? 0 : Integer.parseInt(doc.getString("projectStatus"))));
            /**
             * 3601 流程提交OA，取值 项目类别 给 xmlx ————20210525 修改
             * map.put("xmlx", doc.get("projectType") == null ? 0 : (doc.getString("projectType").length() == 0 ? 0 : Integer.parseInt(doc.getString("projectType"))));
             */
            //map.put("xmlx", doc.get("projectCategory") == null ? 0 : (doc.getString("projectCategory").length() == 0 ? 0 : Integer.parseInt(doc.getString("projectCategory"))));
            map.put("xmlx", doc.get("projectCategory") == null ? "" : doc.getString("projectCategory"));
            map.put("yunshu", doc.get("shippingFangshi") == null ? 0 : (doc.getString("shippingFangshi").length() == 0 ? 0 : Integer.parseInt(doc.getString("shippingFangshi"))));
            map.put("sqlb", doc.get("applicationType") == null ? 0 : (doc.getString("applicationType").length() == 0 ? 0 : Integer.parseInt(doc.getString("applicationType"))));
            //设备/物料类别——3备品备件；4行政物资；5工厂设备；6筹建物资。默认值为 3 备品备件。
            map.put("wllb", doc.get("deviceCategory") == null ? 3 : (doc.getString("deviceCategory").length() == 0 ? 0 : Integer.parseInt(doc.getString("deviceCategory"))));
            map.put("xmh", doc.get("projectCode") == null ? "" : doc.getString("projectCode"));
            map.put("cgdd", doc.get("purchaseLocation") == null ? 0 : Integer.parseInt(doc.getString("purchaseLocation")));
            map.put("hjjeRMB", doc.get("estimateCost") == null ? 0 : (doc.getString("estimateCost").length() == 0 ? 0 : Double.parseDouble(doc.getString("estimateCost"))));
            map.put("yqdhrq", doc.get("dateRequired") == null ? "" : doc.getString("dateRequired"));
            map.put("fydep", 0);
            map.put("spmsurl", "");
            map.put("spmsordernum", spmsId);
            map.put("facdept", 0);
            map.put("beizhu", "");
            map.put("xiangguanliucheng", "");
            map.put("bianhao", "");
            map.put("fujian", "");
            //map.put("fengongsi", spmsUser.getSubcompanyId() == null ? "" : spmsUser.getSubcompanyId());
            /** 分公司字段取值修改 20210804 */
            map.put("fengongsi", spmsUser.getCompany() == null ? "" : spmsUser.getCompany());
            map.put("fendian", spmsUser.getBranchPoint() == null ? "" : spmsUser.getBranchPoint());
            map.put("fenxian", spmsUser.getBranchLine() == null ? "" : spmsUser.getBranchLine());

            MainTableInfo wmi = new MainTableInfo();
            Property[] wrti = new Property[map.size()];
            int i = 0;
            for (Map.Entry<String, Object> entry : map.entrySet()){
                wrti[i] = new Property();
                wrti[i].setName(entry.getKey());
                wrti[i].setValue(entry.getValue().toString());
                i ++;
            }
            wmi.setProperty(wrti);
            reqinfo.setMainTableInfo(wmi);
            /** 请求OA内容记录 */
            oaService.iSysLogService.addSubmitOaRecord("3", SPMS_SUBMIT_OA, "添加", spmsUser.getUserId(),
                    "com.sunda.spmsweb.oaservice.createRequest3601()", "", JSON.toJSONString(reqinfo), "WebService", doc.toJSONString(), spmsId);

            // 生成待办 ，返回待办id
            String reqid = wfproxy.createRequest(reqinfo);
            // 返回大于0 的数字则调用成功
            System.out.println("reqid ======== " + reqid);
            return Integer.parseInt(reqid);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
            return 0;
        }
    }

    /**
     * 创建物料申请流程
     * @param doc
     * @param fileUrl
     * @param spmsUser
     * @return
     */
    public int createRequest0915(JSONObject doc, String fileName, String fileUrl, SpmsUser spmsUser){
        RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy-MM-dd");  //日期格式化

            RequestInfo reqinfo = new RequestInfo();
            reqinfo.setCreatorid(spmsUser.getWorkId());
            /** OA workflow id 0915 : 520 正式； */
            reqinfo.setWorkflowid(workflow0915);
            reqinfo.setRequestlevel("0");
            reqinfo.setRemindtype("0");
            reqinfo.setIsNextFlow("1");
            reqinfo.setDescription("0915 SAP新增物料申请单-" + spmsUser.getLastName() + "-" + simpleDateFormat.format(System.currentTimeMillis()) + "-" + doc.getString("applicationId"));

            Map<String, Object> map = new HashMap<>();
            map.put("workflowdate", simpleDateFormat.format(System.currentTimeMillis()));
            map.put("requestuserid", spmsUser.getWorkId() == null ? "" : spmsUser.getWorkId());
            map.put("dep", spmsUser.getDeptId() == null  ? "" : spmsUser.getDeptId());
            map.put("jobtitle", spmsUser.getPositionId() == null  ? "" : spmsUser.getPositionId());
            map.put("workcode", spmsUser.getUserId() == null ? "" : spmsUser.getUserId());
            map.put("remarks", "");
            map.put("bianhao", "");
            map.put("sub", spmsUser.getBranchLine() == null ? "" : spmsUser.getBranchLine());
            map.put("fendian", spmsUser.getBranchPoint() == null ? "" : spmsUser.getBranchPoint());
            map.put("fenxian", spmsUser.getCompany() == null ? "" : spmsUser.getCompany());
            map.put("cgwl", "0");
            map.put("zb100", "18571");
            map.put("wlsx", "0");
            map.put("sfbdcg", "4");
            map.put("productline", "3");
            map.put("spmsordernum", doc.getString("applicationId") == null ? "" : doc.getString("applicationId"));
            map.put("workfile", fileUrl == null ? "" : fileUrl);
            map.put("cpx", doc.getString("cpx") == null ? "" : doc.getString("cpx"));

            MainTableInfo wmi = new MainTableInfo();
            Property[] wrti = new Property[map.size()];
            int i = 0;
            for (Map.Entry<String, Object> entry : map.entrySet()){
                wrti[i] = new Property();
                wrti[i].setName(entry.getKey());
                wrti[i].setValue(entry.getValue().toString());
                if (entry.getKey().equals("workfile")){
                    wrti[i].setType("http:" + "附件10-备品备件SAP物料申请表.xlsx");
                }
                i++;
            }
            wmi.setProperty(wrti);
            reqinfo.setMainTableInfo(wmi);
            /** 请求OA内容记录 */
            oaService.iSysLogService.addSubmitOaRecord("3", MATERIAL_APPLICATION_INIT, "添加", spmsUser.getUserId(),
                    "com.sunda.spmsweb.oaservice.createRequest0915()", "", JSON.toJSONString(reqinfo), "WebService",
                    doc.toJSONString(), doc.getString("applicationUuid"));
            // 生成待办 ，返回待办id
            String reqid = wfproxy.createRequest(reqinfo);
            // 返回大于0 的数字则调用成功
            System.out.println("reqid ======== " + reqid);
            return Integer.parseInt(reqid);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
            return 0;
        }
    }

    public List<Map<String, Object>> getOALog(String requestId){
        WorkflowDataPortTypeProxy proxy = new WorkflowDataPortTypeProxy();
        try {
            com.sunda.business.soa.hr.po.WorkflowLogs[] hhLogs = proxy.getWorkflowLogsByReqid(requestId);
            List<Map<String, Object>> mapList = new ArrayList<>();
            int i = 1;
            for(com.sunda.business.soa.hr.po.WorkflowLogs hh : hhLogs) {

                Map<String, Object> map = new HashMap<>();
                map.put("requestId", hh.getRequestid());
                map.put("opter", hh.getOpter());
                map.put("nodeName", hh.getNodename());
                //map.put("nodeName", i + "." + hh.getNodename().split("、")[1].trim());
                map.put("operateTime", hh.getOperatetime());
                map.put("optStatus", hh.getOptstatus());
                map.put("receiveTime", hh.getReceivetime());
                mapList.add(map);
                i += 1;
            }
            return mapList;
        } catch (RemoteException e) {
            e.printStackTrace();
            return null;
        }
    }

}
